package com.example.neptune.zyfypt_109zj.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.neptune.zyfypt_109zj.R;
import com.example.neptune.zyfypt_109zj.iface.RegisterListener;
import com.example.neptune.zyfypt_109zj.model.RegisterModel;


public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button submit;
    private EditText name, pwd,tel;
    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toast.makeText(this, "Amicool注册", Toast.LENGTH_SHORT).show();
        init();

        Button button=(Button)findViewById(R.id.buttonfh);
        button.setOnClickListener(this);


    }

    private void init() {
        name = (EditText)findViewById(R.id.editText3);
        pwd = (EditText)findViewById(R.id.editText4);
        tel = (EditText)findViewById(R.id.editText5);
        submit = (Button)findViewById(R.id.button4);

        submit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.buttonfh:
                finish();
                break;
            case R.id.button4:
                System.out.println("注册——提交");
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(name.getText().toString(),
                        pwd.getText().toString(),
                        tel.getText().toString(),
                        registerListener);

        }
    }
}
